package org.lld.im.service.group.controller;

import org.lld.im.common.ResponseVO;
import org.lld.im.service.group.model.req.*;
import org.lld.im.service.group.service.GroupMessageService;
import org.lld.im.service.group.service.ImGroupService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author: LunBoWang
 * @description: 群组模块控制层
 * @date: 2025/3/17 下午7:29
 * @version: 1.0
 */
@RestController
@RequestMapping("v1/group")
public class ImGroupController {
    @Resource
    ImGroupService imGroupService;

    @Resource
    GroupMessageService groupMessageService;

    // 导入群聊
    @PostMapping("/importGroup")
    public ResponseVO importGroup(@RequestBody @Validated ImportGroupReq req,Integer appId,String identifier) {
        req.setAppId(appId);
        req.setOperator(identifier);
        return imGroupService.importGroup(req);
    }

    // 创建群聊
    @PostMapping("/createGroup")
    public ResponseVO createGroup(@RequestBody @Validated CreateGroupReq req, Integer appId, String identifier) {
        req.setAppId(appId);
        req.setOperator(identifier);
        return imGroupService.createGroup(req);
    }

    // 修改群聊信息
    @PutMapping("/update")
    public ResponseVO update(@RequestBody @Validated UpdateGroupReq req, Integer appId, String identifier) {
        req.setAppId(appId);
        req.setOperator(identifier);
        return imGroupService.updateBaseGroupInfo(req);
    }

    //获取群聊信息
    @GetMapping("/getGroupInfo")
    public ResponseVO getGroupInfo(@RequestBody @Validated GetGroupReq req, Integer appId, String identifier) {
        req.setAppId(appId);
        req.setOperator(identifier);
        return imGroupService.getGroup(req);
    }

    //获取用户加入的群聊
    @GetMapping("/getJoinedRequest")
    public ResponseVO getJoinedRequest(@RequestBody @Validated GetJoinedGroupReq req, Integer appId, String identifier) {
        req.setAppId(appId);
        req.setOperator(identifier);
        return imGroupService.getJoinedGroup(req);
    }

    //解散群聊
    @DeleteMapping("/destroyGroup")
    public ResponseVO destroyGroup(@RequestBody @Validated DestroyGroupReq req, Integer appId, String identifier) {
        req.setAppId(appId);
        req.setOperator(identifier);
        return imGroupService.destroyGroup(req);
    }

    //转让群聊
    @PutMapping("/transferGroup")
    public ResponseVO transferGroup(@RequestBody @Validated TransferGroupReq req, Integer appId, String identifier) {
        req.setAppId(appId);
        req.setOperator(identifier);
        return imGroupService.transferGroup(req);
    }

    // 禁言群
    @PutMapping("/forbidSendMessage")
    public ResponseVO forbidSendMessage(@RequestBody @Validated MuteGroupReq req, Integer appId, String identifier) {
        req.setAppId(appId);
        req.setOperator(identifier);
        return imGroupService.muteGroup(req);
    }

    @RequestMapping("/sendMessage")
    public ResponseVO sendMessage(@RequestBody @Validated SendGroupMessageReq req, Integer appId, String identifier) {
        req.setAppId(appId);
        req.setOperator(identifier);
        return ResponseVO.successResponse(groupMessageService.send(req));
    }
}
